package clue.editor;

import java.awt.Component;
import java.awt.GridLayout;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import objects.Character;
import objects.ClueComboBox;
import objects.Room;
import objects.Weapon;

public class EnvelopePanel extends JPanel{
	
	private static final long serialVersionUID = 1L;

	public EnvelopePanel()
	{
		setLayout(new GridLayout(0, 1, 0, 0));
		
		JPanel panel = new JPanel();
		add(panel);
		//setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		JLabel lblEnvelope = new JLabel("Envelope");
		panel.add(lblEnvelope);
		
		JPanel panel_1 = new JPanel();
		add(panel_1);
		
		JComboBox<Character> comboBox = new ClueComboBox<Character>();
		panel_1.add(comboBox);
		comboBox.setModel(new DefaultComboBoxModel<Character>(Character.values()));
		
		JComboBox<Room> comboBox_1 = new ClueComboBox<Room>();
		panel_1.add(comboBox_1);
		comboBox_1.setModel(new DefaultComboBoxModel<Room>(Room.values()));
		
		JComboBox<Weapon> comboBox_2 = new ClueComboBox<Weapon>();
		panel_1.add(comboBox_2);
		comboBox_2.setModel(new DefaultComboBoxModel<Weapon>(Weapon.values()));
		
		
	}
	
	/**
	 * The method reset the envelope to the starting state
	 */
	public void resetEnvelope()
	{
		for (Component component : ((JPanel) getComponent(1)).getComponents()) {
			if (component instanceof ClueComboBox)
			{
				if (((ClueComboBox<?>) component).getSelectedItem() instanceof Weapon)
				{
					((ClueComboBox<?>) component).setSelectedItem(Weapon.values()[0]);
				}
				else if (((ClueComboBox<?>) component).getSelectedItem() instanceof Character) 
				{
					((ClueComboBox<?>) component).setSelectedItem(Character.values()[0]);
				}
				else if (((ClueComboBox<?>) component).getSelectedItem() instanceof Room)
				{
					((ClueComboBox<?>) component).setSelectedItem(Room.values()[0]);
				}
			}
		}
		
		validate();
		repaint();
	}
}
